var express = require('express')
var app = express()
var http = require('http').Server(app);
var multer = require('multer');
var upload = multer()
var io = require('socket.io')(http)
var router = express.Router();
var _ = require('underscore')
var URL = require('url');
app.get('/', (req, res, next) => {
  res.sendFile(__dirname + '/index.html');
})

app.get('/test', (req, res, next) => {
  var data = URL.parse(req.url, true).query
  var socketid = data.key
  res.send(req.url)
  io.sockets.connected[socketid].emit('chat message', data.name+':'+'哈哈哈，别😰了，你被监控了！！！！'); 
})

http.listen(3000, (req, res, next)=>{
  console.log('listening on *:3000');
})

io.on('connection', (socket) => {
  socket.on('disconnect', function(){
    console.log('user disconnected');
  });
  socket.on('chat message', function(msg){
    io.emit('chat message', socket.id+':'+msg); 
  });
});
